package com.ruicar.afs.cloud.afscase.risk.controller;

import cn.hutool.core.util.StrUtil;
import com.ruicar.afs.cloud.afscase.risk.vo.HandInvokeAntiFraudParam;
import com.ruicar.afs.cloud.afscase.risk.service.CaseTortoiseService;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.risk.api.enums.tortoise.GwtTortoiseAntiFraudCallStep;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Description
 * @Author Peng Jinbo
 * @Date 2020/08/10 23:00
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/antiFraudHand")
public class AntiFraudHandController {

    /**
     * Case tortoise service
     */
    private CaseTortoiseService caseTortoiseService;

    /**
     * @Description 手动触发玄武反欺诈
     * @Author Peng_Jinbo
     * @Date 2020/8/10 17:22
     */
    @PostMapping("/handInvokeAntiFraud")
    public IResponse handInvokeAntiFraud(@RequestBody HandInvokeAntiFraudParam param){
        if(Objects.nonNull(param) && StringUtils.isNotBlank(param.getApplyNo())){
            Assert.isTrue(StrUtil.isNotBlank(param.getCallStep()),"调用步骤不可为空");
            GwtTortoiseAntiFraudCallStep callStep = (GwtTortoiseAntiFraudCallStep) AfsEnumUtil.getEnum(param.getCallStep(),GwtTortoiseAntiFraudCallStep.class);
            Assert.notNull(callStep,String.format("非法调用步骤 : %s",param.getCallStep()));
            caseTortoiseService.signalFraudHand(param.getApplyNo(), callStep);
            return IResponse.success("操作成功");
        }else{
            return IResponse.fail("申请编号为空，手动触发反欺诈失败");
        }
    }

}
